package com.zgg.core.config

import com.zgg.MainStart
import io.vertx.core.json.JsonObject
import io.vertx.ext.mongo.MongoClient as _MongoClient

/**
 * @author zhouganggui
 * @email 1641583112@qq.com
 * @date 2021/6/30 11:42
 * @Descript:
 */
class MongoClient() {
    companion object {
        var defMongoClient: _MongoClient? = null

        fun connect(conf: JsonObject, db_name: String? = null) {
            val config = conf.copy()
            if (db_name != null) {
                config.put("db_name", db_name)
            }
            if (!config.containsKey("authSource")) {
                config.put("authSource", "admin")
            }
            config.put("waitQueueMultiple", 20000)
            config.put("maxIdleTimeMS", 1000 * 60)
            defMongoClient = _MongoClient.createShared(MainStart.vertx, config)
        }
    }
}